package net.shenru.data;

import java.sql.SQLException;

import net.shenru.modle.map.Bus;
import net.shenru.os.utlis.SrLog;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;

import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;

public class DatabaseHelper extends OrmLiteSqliteOpenHelper{


	private static final String TAG = DatabaseHelper.class.getSimpleName();
	
	private static final String database_name = "shenru.db";
	private static final int database_version = 1;
	
	
	public DatabaseHelper(Context context, String databaseName, CursorFactory factory, int databaseVersion) {
		super(context, database_name, null, database_version);
	}

	@Override
	public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
		try {
			TableUtils.clearTable(connectionSource, Bus.class);
		} catch (SQLException e) {
			SrLog.i(TAG, "onCreate table error:%s", e.toString());
		}
	}

	@Override
	public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) {
		try {
			TableUtils.dropTable(connectionSource, Bus.class, true);
		} catch (SQLException e) {
			SrLog.i(TAG, "onCreate table error:%s", e.toString());
		}
	}


}
